import threading
import taskConfig
import time

class clientFuncs(threading.Thread):
	rpcObj	= None
	taskKey	= None
	prevTime= None
	def __init__(self, rpcObj, key):
		threading.Thread.__init__(self)
		super(clientFuncs, self).__init__()
		self._stop		= threading.Event()
		self.rpcObj		= rpcObj
		self.taskKey	= key
		self.prevTime	= int(time.time())
	
	def stop(self):
		self._stop.set()

	def run(self):
		while 1:
			if self._stop.isSet() == True:
				break
			time.sleep(taskConfig.taskHeartBeatTime)
			curTime	= int(time.time())
			if (curTime - self.prevTime) > taskConfig.taskHeartBeatTime:
				self.rpcObj.iAmAlive(self.taskKey)
				self.prevTime	= curTime
		
